BEGIN {
	printf("scenarioTime \tduration \thaggleTime \thaggleDelay \tcnt cntDiscovered\n", 
		meanScenarioTime, sqrt(varScenarioTime), 
		meanDuration, sqrt(varDuration),
		meanHaggleTime, sqrt(varHaggleTime), 
		meanHaggleDelay, sqrt(varHaggleDelay),
		cnt, cntDiscovered);
}

{
	scenarioTime = $2;			# time into the scenario that the link goes up
	expNum = $6;				# experiment
	duration = $8;				# connectionTime
	haggleDelay = $9;			# time until haggle discovers link
	haggleTime = scenarioTime + haggleDelay;

	nodeA = $3;
	nodeB = $4;
	
	if ((prevNodeA != nodeA) || (prevNodeB != nodeB) || (prevScenarioTime-scenarioTime > 500) || (scenarioTime-prevScenarioTime > 500)) {

		asort(aScenarioTime);
		asort(aDuration);
		asort(aHaggleTime);
		asort(aHaggleDelay);

		if (cnt > 0) {
			cntDiscovered=0;

			for (e=0;e<cnt;e++) {
				sumScenarioTime += aScenarioTime[e];
				sumDuration += aDuration[e];
				if (aHaggleDelay[e] < aDuration[e]) {
					cntDiscovered++;
					sumHaggleTime += aHaggleTime[e];
					sumHaggleDelay += aHaggleDelay[e];
				}
			}
			meanScenarioTime = sumScenarioTime / cnt;
			meanDuration = sumDuration /cnt;
			if (cntDiscovered > 0) {
				meanHaggleTime = sumHaggleTime / cntDiscovered;
				meanHaggleDelay = sumHaggleDelay / cntDiscovered;
			}

			for (e=0;e<cnt;e++) {
				sumScenarioTimeVar += (aScenarioTime[e] - meanScenarioTime)^2;
				sumDurationVar += (aDuration[e] - meanDuration)^2;
				if (aHaggleDelay[e] < aDuration[e]) {
					sumHaggleTimeVar += (aHaggleTime[e] - meanHaggleTime)^2;
					sumHaggleDelayVar += (aHaggleDelay[e] - meanHaggleDelay)^2;
				}
			}
			varScenarioTime = sumScenarioTimeVar / cnt;
			varDuration = sumDuration / cnt;
			if (cntDiscovered > 0) {
				varHaggleTime = sumHaggleTimeVar / cntDiscovered;
				varHaggleDelay = sumHaggleDelayVar /cntDiscovered;
			}
			
			printf("%ld %0.2f \t%ld %0.2f \t%ld %0.2f \t%ld %0.2f \t%d %d\n", 
				meanScenarioTime, sqrt(varScenarioTime), 
				meanDuration, sqrt(varDuration),
				meanHaggleTime, sqrt(varHaggleTime), 
				meanHaggleDelay, sqrt(varHaggleDelay),
				cnt, cntDiscovered);
		}
	

		sumScenarioTime = 0;
		sumDuration = 0;
		sumHaggleTime = 0;
		sumHaggleDelay = 0;

		sumScenarioTimeVar = 0;
		sumDurationVar = 0;
		sumHaggleTimeVar = 0;
		sumHaggleDelayVar = 0;
	
		meanScenarioTime = 0;
		meanDuration = 0;
		meanHaggleTime = 0;
		meanHaggleDelay = 0;

		varScenarioTime = 0;
		varDuration = 0;
		varHaggleTime = 0;
		varHaggleDelay = 0;

		delete aScenarioTime;
		delete aDuration;
		delete aHaggleTime;
		delete aHaggleDelay;

		cnt = 0;
	}

	aScenarioTime[cnt] = scenarioTime;
	aDuration[cnt] = duration;
	aHaggleTime[cnt] = haggleTime;
	aHaggleDelay[cnt] = haggleDelay;

	cnt++;
	prevNodeA = nodeA;
	prevNodeB = nodeB;
	prevScenarioTime = scenarioTime;
}